﻿using ITXHWEB.Models;
using ReflectionStudio.Core.Events;
using System;
using System.Data;
using System.Web.Mvc;
using WPFExcelReport;
using WPFExcelReport.Helpers;
using ITXHWEB.Infrastructure;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace ITXHWEB.Controllers
{
    public partial class AMSTAMMController
    {
        [ChildActionOnly]
        public ActionResult SQITABLE(string returnUrl)
        {
            ModelState.Clear();
            ViewBag.ReturnUrl = returnUrl;
            ViewBag.IsAMReady = MABF.IsAMReady;
            if (!MABF.IsAMReady)
            {
                INFO = "请扫描有效的设备";
            }
            return PartialView(MABF.MAM);
        }
        [HttpPost]
        [AllowAnonymous]
        [ValidateAntiForgeryToken]
        public ActionResult SQITABLE(AMSTAMMModel model, string returnUrl)
        {
            try
            {
                ModelState.Clear();
                ViewBag.IsAMReady = MABF.IsAMReady;
                AMCHK(model);
            }
            catch (Exception ex)
            {
                INFO = ex.Message;
                Tracer.Error(ex.StackTrace, ex);
            }
            return RedirectToAction(MAPP, MAPP);
        }
        public void AMCHK(AMSTAMMModel model)
        {

            MABF.IsAMReady = false;
            if (model.MACHINEID == null)
                return;
            var result = AMS.Where(p => p.MACHINEID.Trim() == model.MACHINEID.Trim()).OrderByDescending(p => p.MACHINEID);
            int remain = result.Count();
            foreach (var m in result)
            {
                MABF.MACHINEID = m.MACHINEID;
                MABF.MAM = m;
                MABF.SHIFT = model.SHIFT;
                MABF.IsAMReady = true;
            }
        }  
    }
}
